package com.qaml.mes.device.controller;


import com.earth.output.OutputMessage;
import com.earth.page.PageResponse;
import com.earth.user.AuthSsoContext;
import com.earth.user.SsoLoginUser;
import com.qaml.mes.device.api.EqpInfoService;
import com.qaml.mes.device.dto.eqp.EqpInfoDTO;
import com.qaml.mes.device.dto.eqp.EqpInfoIdDTO;
import com.qaml.mes.device.dto.eqp.EqpInfoListDTO;
import com.qaml.mes.device.vo.eqp.EqpInfoListVO;
import com.qaml.mes.device.vo.eqp.EqpInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备信息表 前端控制器
 * </p>
 *
 * @author leikai
 * @since 2024-02-27
 */
@Api(tags = "设备信息")
@RestController
@RequestMapping("/eqpInfo")
public class EqpInfoController {

    @Resource
    private EqpInfoService eqpInfoService;

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "设备信息-新增修改(Web)", notes = "设备信息-新增修改")
    public OutputMessage<String> saveOrUpdate(@RequestBody @Validated EqpInfoDTO eqpInfoDTO) {
        eqpInfoService.saveOrUpdate(eqpInfoDTO);
        return OutputMessage.success("保存成功");
    }


    /**
     * 逻辑删除 删除设备
     *
     * @param eqpInfoDTO
     * @return
     */
    @PostMapping("/deleteById")
    @ApiOperation(value = "设备信息-删除(Web)", notes = "设备信息-删除")
    public OutputMessage<String> delete(@RequestBody EqpInfoDTO eqpInfoDTO) {
        eqpInfoService.deleteById(eqpInfoDTO.getId());
        return OutputMessage.success("设备删除成功！");
    }

    /**
     * 获取设备详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getById")
    @ApiOperation(value = "设备信息-详情-根据id获取(Web)", notes = "设备信息-详情-根据id获取")
    public OutputMessage<EqpInfoVO> getById(@RequestParam("id") String id) {
        return OutputMessage.success(eqpInfoService.getById(id));
    }

    /**
     * 获取设备列表信息(分页) --web端
     */
    @PostMapping("/eqpInfoList")
    @ApiOperation(value = "设备信息-列表-根据id获取(Web)", notes = "设备信息-列表-根据id获取")
    public PageResponse<EqpInfoListVO> list(@RequestBody EqpInfoListDTO eqpInfoListDTO) {
        return eqpInfoService.getEqpInfoVOList(eqpInfoListDTO);
    }

    @PostMapping("/enableEqp")
    @ApiOperation(value = "设备信息-启用(Web)", notes = "设备信息-启用")
    public OutputMessage<String> enableEqp(@RequestBody @Validated EqpInfoIdDTO id) {
        eqpInfoService.enableEqp(id);
        return OutputMessage.success("设备启用成功！");
    }

    @PostMapping("/disableEqp")
    @ApiOperation(value = "设备信息-禁用(Web)", notes = "设备信息-禁用")
    public OutputMessage<String> disableEqp(@RequestBody @Validated EqpInfoIdDTO id) {
        eqpInfoService.disableEqp(id);
        return OutputMessage.success("设备禁用成功！");
    }

    /**
     * 获取设备列表  -->接口
     */
    @ApiOperation(value = "设备信息-列表(Web)", notes = "设备信息-列表")
    @GetMapping("/getEqpInfoVOS")
    public OutputMessage<List<EqpInfoVO>> eqpCodeList() {
        return OutputMessage.success(eqpInfoService.getEqpCodeList());
    }
}
